package com.wtc.homework;

/**
 * @author 马可
 * @version 1.0
 * 注册处理题
 * 2023/5/26
 * IntelliJ IDEA
 */
public class Homework09 {
    public static void main(String[] args) {
        try {
            creatUser("", "1234568888", "1489512614@qq.com");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    public static void creatUser(String name, String passwd, String email) {
        if (!(name.length() == 2 || name.length() == 3 || name.length() == 4)) {
            throw new RuntimeException("用户名长度不正确！");
        }

        if (passwd.length() != 6) {
            throw new RuntimeException("密码长度不正确，必须是六位！");
        } else {
            try {
                int passwdNew = Integer.parseInt(passwd);
            } catch (NumberFormatException e) {
                throw new RuntimeException("密码设置不正确，必须全是数字！");
            }
        }
        if (!(email.lastIndexOf("@") < email.lastIndexOf(".") &&
                email.lastIndexOf("@") != -1 && email.lastIndexOf(".") != -1)) {
            throw new RuntimeException("邮箱格式错误！");
        }
        System.out.println("注册成功！");
    }
}